//品牌管理
var id;

var workId; // 工种
$(function(){

    worklist()
    id = ly.getUrlParam("id");
	
 
        $("#taskCategories").getSelect({
            type:"screen",
            label:"任务类型：",
            asName:"taskCategories",  
            code:"taskCategories"
        });
        $("#taskStatus").getSelect({
            type:"screen",
            label:"任务状态：",
            asName:"taskStatus",
            code:"taskStatus"
        });
  
        
	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).val()+',';
		});
		if(c!= null && c!=''){
			deleteBrand(c);
		}else{
			ly.toast("请选择删除项");
		}
		
    });
    

    
        $('#taskList').getList({
            "initData":{
                "num":1,
                "size":10,
                "taskId":id,
                // 'taskTime':'2019-08-21',
            },
            "url":site.apiUrl+"/back/task/selectTaskReceivingRecordsByTaskId",// 数据请求url
            "type": "POST",
            "checkname":"datachk", //选择器名称，为空不显示选择器
            "col":[  //数据列
                {"field":"taskName","display":"任务名称","width":"1.5"},
                {"field":"taskTypeDisplay","display":"任务类型","width":"1.5"},
                {"field":"nickName","display":"任务发放人","width":"1.5"},
                {"field":"executorName","display":"任务执行人","width":"1.5"},
                {"field":"workName","display":"任务工种","width":"1.5"},
                {"field":"taskStartTime","display":"任务日期","width":"1.5"},
                {"field":"taskStatusDisplay","display":"任务状态","width":"1.5"},
            ],
            "option":[ //操作按钮配置
                {"icon":"view","tip":"查看","fun":"brandView('{{id}}','{{taskTypeDisplay}}','{{nickName}}','{{executorName}}','{{taskStatusDisplay}}','{{workName}}' )"},  //icon: view,edit,add,del
                // {"icon":"edit","tip":"编辑","fun":"newPage('{{id}}')"},  // 花括号内可以对应相关字段
                // {"icon":"del","tip":"删除","fun":"deleteBrand('{{id}}')"}
            ]
        });    
     



});



function worklist() {       
	request({
		url: site.apiUrl+"/back/worker/selectWorkerList",
		data: {
			'num': 1,
            'size': 100,
            'isUsing':1
		},
        type: "get",
        ajaxform:true,
		callback: function (f) {
             var list = f.result.list; 
			if (f.code == "rest.success") {
                console.log(list);
                var html = '';
              
                $('#worklist').html('<option value="">全部</option>')
                for (let i = 0; i < list.length; i++) {
                    html+=' <option value='+list[i].id+'>'+list[i].workerName+'</option>'
                }
                $('#worklist').append(html)
			}
		}
	});
}
$('#worklist').on('change',function(){
    $('#taskList').getList({
        "initData":{
            "num":1,
            "size":10,
            "taskId":id,
            //'taskTime':'2019-08-22',
            'workId':$(this).val()
        },
        "url":site.apiUrl+"/back/task/selectTaskReceivingRecordsByTaskId",// 数据请求url
        "type":"POST",
        "checkname":"datachk", //选择器名称，为空不显示选择器
        "col":[  //数据列
            {"field":"taskName","display":"任务名称","width":"1.5"},
            {"field":"taskTypeDisplay","display":"任务类型","width":"1.5"},
            {"field":"nickName","display":"任务发放人","width":"1.5"},
            {"field":"executorName","display":"任务执行人","width":"1.5"},
            {"field":"workName","display":"所属工种","width":"1.5"},
            {"field":"taskStartTime","display":"任务日期","width":"1.5"},
            {"field":"taskStatusDisplay","display":"任务状态","width":"1.5"},
        ],
        "option":[ //操作按钮配置
            {"icon":"view","tip":"查看","fun":"brandView('{{id}}','{{taskTypeDisplay}}','{{nickName}}','{{executorName}}','{{taskStatusDisplay}}','{{workName}}' )"},  //icon: view,edit,add,del
            // {"icon":"edit","tip":"编辑","fun":"newPage('{{id}}')"},  // 花括号内可以对应相关字段
            // {"icon":"del","tip":"删除","fun":"deleteBrand('{{id}}')"}
        ]
    });   

})







//编辑
function brandView(id,taskTypeDisplay,nickName,executorName,taskStatusDisplay,workName){
	ly.goto("task-list-newPage-creat.html?id="+id+"&taskTypeDisplay="+taskTypeDisplay+"&nickName="+nickName+"&executorName="+executorName+"&taskStatusDisplay="+taskStatusDisplay+"&workName="+workName+"")
}

//删除
function deleteBrand(id){
	var url = site.gateUrl+"/back/task/deleteTaskByIdOnBack";
	ly.confirm("你确认删除吗？",function(){
		request({
			url:url,
			data:{"ids":id},
			type:"get",
			'ajaxform':true,
			callback:function(f) {
				console.log(f);
				if(f.code=="rest.success"){
					ly.toast("删除成功");
					$("#taskList").getList.refresh();//刷新当前分页
				}else{
					ly.toast(f.desc);
				}
			}
		});	
	});
}